package com.study.sxc.service;

import com.study.sxc.Dao.ILabDao;
import com.study.sxc.Entity.Lab;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class labService {

    private static final Logger log = LoggerFactory.getLogger(labService.class);

    @Resource
    ILabDao labDao;

    public List<Lab> getLabs(List<Integer> ids) {
        log.info("查询机房列表，参数：{}", ids);
        List<Lab> labs = labDao.getLabs(ids);
        log.info("DAO层返回数据：{}", labs);
        if(labs == null || labs.isEmpty()) {
            return new ArrayList<>();
        }
        return labs;
    }

    public int addLab(Lab lab) {
        log.info("新增机房，参数：{}", lab);
        int result = labDao.addLab(lab);
        log.info("新增机房结果：{}", result);
        return result;
    }

    public int updateLab(Lab lab) {
        log.info("更新机房，参数：{}", lab);
        int result = labDao.updateLab(lab);
        log.info("更新机房结果：{}", result);
        return result;
    }

    public int deleteLab(Integer id) {
        log.info("删除机房，参数：{}", id);
        int result = labDao.deleteLab(id);
        log.info("删除机房结果：{}", result);
        return result;
    }

    public Lab getLabById(Integer id) {
        return labDao.getLabById(id);
    }

    public List<Lab> getAllLabs() {
        // 查询所有机房
        return labDao.getAllLabs();
    }
}

